﻿@{
    ViewBag.Title = "Uedit";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
}

<form id="form1" method="post">
            @Html.Partial("~/Views/Modular/Toolbars.cshtml")
        <div name="Base" title="用户资料" style="height:100%;overflow:hidden;margin-top:15px;margin-left:20px">
            <table style="width:100%;">
                <tr>
                    <td width="80px" height ="35px" align="right">自定义码：</td>
                    <td width="200px" height ="35px">                        
                        <input id="FUses_name" name="FUses_name" class="mini-textbox "  style="width:200px;"  TabIndex="1"/>
                    </td>
                    <td width="80px" height ="35px" align="right">用户编码：</td>
                    <td width="200px" height ="35px">
                        <input name="FNumber" id="FNumber" class="mini-textbox" style="width:190px;" value="" TabIndex="3" enabled="@ViewBag.NumberEnabled"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">用户名称：</td>
                    <td width="200px" height ="35px">
                        <input id="FName" name="FName" class="mini-textbox " style="width:200px;" TabIndex="2"/>
                    </td>
                    <td width="80px" height ="35px" align="right">用户类型：</td>
                    <td width="200px" height ="35px">
                       <input id="FType" name="FType" class="mini-combobox" style="width:190px;" showNullItem="false" 
                            allowInput="false" align="left" value ="1" data ="comType"/> 
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">联系电话：</td>
                    <td width="200px" height ="35px">
                        <input name="FTelephone" id="FTelephone" class="mini-textbox" style="width:200px;"  value="" TabIndex="4"/>
                    </td>
                    <td width="80px" height ="35px" align="right">联系地址：</td>
                    <td width="200px" height ="35px">
                        <input id="FAddress" name="FAddress" class="mini-textbox "  style="width:190px;"  TabIndex="5"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">用户权限：</td>
                    <td width="200px" height ="35px">
                        @Html.Partial("~/Views/Modular/LookupUserAuthority.cshtml")
                    </td>
                    <td width="80px" height ="35px" align="right"> &nbsp;&nbsp;备&nbsp;&nbsp;注：</td>
                    <td width="200px" height ="35px">    
                        <input name="FRemark" id="FRemark" class="mini-textbox" style="width:190px;"  value="" TabIndex="6"/>                     
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">登录密码：</td>
                    <td width="200px" height ="35px">
                        <input id="FPassword" name="FPassword" class="mini-textbox"  value="000000" style="width:200px;"/>
                    </td>
                    <td width="80px" height ="35px" align="right"></td>
                    <td width="200px" height ="35px">                     
                    </td>
                </tr>
            </table>
            <br />
        </div>
    <input name="FItemID" class="mini-hidden" />
</form>


<script>
    var comType = [{ "id": "0", "text": "管理用户" },{ "id": "1", "text": "前台用户" },
                   { "id": "2", "text": "经营助手" }, { "id": "3", "text": "关联导购员用户" },
                   { "id": "4", "text": "关联批发客户用户" }];

    function FormShown() {
        mini.parse();
        LoadListData();
    }

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            NewInfo();
        }
        else {
            $.post("GetUser", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                mini.getbyName("FAuthorityID").setText(mdata.data[0].FAuthorityNumber);
                mini.getbyName("FPassword").setValue("******");
                mini.getbyName("FPassword").setEnabled(false);
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("");
        mini.getbyName("FNumber").setValue("");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FTelephone").setValue("");
        mini.getbyName("FUses_name").setValue("");
        mini.getbyName("FAddress").setValue("");
        mini.getbyName("FPassword").setValue("");
        mini.getbyName("FRemark").setValue("");
        mini.getbyName("FPassword").setValue("000000");
        mini.getbyName("FPassword").setEnabled(true);
        $.post('NewUserInfo', { json: parent.window.getSystemAppID() }, function (data) {
            mini.getbyName("FUses_name").setValue(data);
        });
    }

    //保存资料
    function SaveInfo() {
        if (mini.getbyName("FPassword").getValue() == "") {
            mini.alert("用户密码不能空值");
            return false;
        }
        if (mini.getbyName("FNumber").getValue().length <= 6 && mini.getbyName("FNumber").getValue().length > 50) {
            mini.alert("编码必须大于等于6个字符，不能多于50个字符");
            return;
        }
        if (mini.getbyName("FName").getValue().length > 50) {
            mini.alert("用户名不能多于50个字符");
            return;
        }
        mini.getbyName("SaveInfo").setEnabled(false);
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            mini.getbyName("SaveInfo").setEnabled(true);
            return;
        }
        var data = form.getData(true, false);

        var json = mini.encode(data);
        $.post("SaveUserInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                mini.alert("异常:"+ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }
</script>